#ifndef EDITOR_H
#define EDITOR_H

#include <Qsci/qsciscintilla.h>
#include <QtCore/QList>

class QListWidget;
class QToolButton;
class QFrame;
class QHBoxLayout;

struct Selection
{
	int startLine;
	int startLineIndex;
	int endLine;
	int endLineIndex;
	Selection() {
		startLine = -1;
		startLineIndex = -1;
		endLine = -1;
		endLineIndex = -1;
	}
	Selection(int sLine,int sLineIndex,int eLine,int eLineIndex) {
		startLine = sLine;
		startLineIndex = sLineIndex;
		endLine = eLine;
		endLineIndex = eLineIndex;
	}
};

typedef QList<Selection> SelectionsList;

class Editor : public QsciScintilla
{
	Q_OBJECT
	signals:
		void contextMenuRequested(int globalX,int globalY);
		void changeFileRequested(int index);
		void filesListStatusChanged(bool show);
	public slots:
		bool find(const QString& expression,bool regExp,bool caseSensitive,bool wholeWord,bool forward,bool fromCursor);
		bool findPreviousEntry();
		bool findNextEntry();
		bool findAndReplaceAllEntries(const QString& expression,const QString& replaceOn,bool regExp,bool caseSensitive,bool wholeWord,bool forward,bool fromCursor);
	
		void unindentSelectedText();
		void commentSelectedText();
		void moveToLineNumber(int number);
	
		void setBookmark();
		void nextBookmark();
		void previousBookmark();
		void unsetAllBookmarks();
	
		void setFilesListStatus(bool show);
		// language influences on highlighting
		//void setProgrammingLanguage(const QString& language);
	public:
		Editor(QWidget *parent = 0);
		
		void setCurrentSelection(const Selection& selection);
		Selection getCurrentSelection() const;
		
		void setEditorIndex(int index);
		int getEditorIndex() const;
		
		void selectItemInFilesList();
		void changeItemTitleInFilesList(int index,const QString& title);
		void removeItemFromFilesList(int index);
		void reduceIndexOfItemsSince(int index);
		void addItemToFilesList(int index,const QString& title);
		
		// View Settings
		void showLinesNumbers(bool show);
		void adjustTextByWidth(bool adjust);
		
		// Get settings from configure file and set them
		void updateSettings();
	private slots:
		// Set width in left panel with bookmarks and lines numbers
		void updateMarginWidth();
		void emitSignalToChangeFile();
		void showOrHideFilesList();
	private:
		// For function "Find previous"
		SelectionsList previousFindEntries;
		int currentFindEntryIndex;
		
		QListWidget *filesListWidget;
	
		QToolButton *zoomInButton;
		QToolButton *zoomOutButton;
		QToolButton *showFilesListButton;
		QFrame *buttonsFrame;
		QHBoxLayout *buttonsFrameLayout;
		int editorIndex;
		
		int currentLineNumber();
		void updateFilesListSize();
	protected:
		void contextMenuEvent(QContextMenuEvent *);
		void resizeEvent(QResizeEvent *);
};

#endif
